
# 设置编译器
set(CMAKE_CROSSCOMPILING TRUE)
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM Generic)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_C_COMPILER_WORKS 1)
set(CMAKE_CXX_COMPILER_WORKS 1)
set(CMAKE_C_COMPILER_FORCED)
set(CMAKE_CXX_COMPILER_FORCED)

SET(TOOLCHAIN_PATH /opt/gcc-arm-none-eabi-9-2020-q2-update)
set(CMAKE_C_COMPILER arm-none-eabi-gcc)
set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
set(CMAKE_SIZE arm-none-eabi-size)
set(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN_PATH})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

# 宏定义
add_definitions(
-DUSE_HAL_DRIVER
-DSTM32F407xx
)

# 编译选项
set(MCU_FLAGS "-mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mthumb")
set(CMAKE_C_FLAGS "${MCU_FLAGS} -Wall -O0 -g -std=gnu99")
set(CMAKE_CXX_FLAGS "${MCU_FLAGS} -Wall -O0 -g -std=gnu99")
add_compile_options(-fdata-sections)
add_compile_options(-ffunction-sections)
add_compile_options(-gdwarf-2)

